/**
 * 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
 * 日    期：2020-12-15
 */
package com.rzico.article.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.annotation.Log;
import com.rzico.article.entity.BillChefAffiliated;
import com.rzico.article.entity.BillFareAffiliated;
import com.rzico.article.service.BillChefAffiliatedService;
import com.rzico.article.service.BillFareAffiliatedService;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.basics.entity.Shop;
import com.rzico.basics.model.ShopVo;
import com.rzico.basics.service.ShopService;
import com.rzico.entity.PageResult;
import com.rzico.entity.Pageable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 名厨关联店铺控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-12-15
 */
@Api(description = "名厨关联店铺接口")
@RestController
@RequestMapping("/billChefAffiliated")
public class BillChefAffiliatedController extends BaseController {

    @Autowired
    private BillChefAffiliatedService billChefAffiliatedService;

    @Autowired
    private ShopService shopService;
    /**
     * 分页查询名厨关联店铺
     *
     * @return
     */
    @ApiOperation("分页查询名厨关联店铺")
    @GetMapping("/list")
    @ApiImplicitParams({@ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "String", paramType = "query") ,
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "chefId", value = "名厨Id", dataType = "Integer", paramType = "query")
    })
    public CommResult<BillChefAffiliated> list(Date startDate, Date endDate, Integer chefId, Pageable pageable) {
        Map<String, Object> params = new HashMap<String, Object>();
        params = buildSortField(params, pageable);
        if (startDate!=null){
            params.put("startDate", startDate);
        }
        if (endDate!=null){
            params.put("endDate", DateUtils.addMilliseconds(DateUtils.addDays(endDate,1),-1));
        }
        if(chefId != null) {
            params.put("chefId", chefId);
        }

        Page<Object> startPage = PageHelper.startPage(pageable.getPageNum(), pageable.getPageSize());
        List<ShopVo> list = shopService.selectChefAffiliatedList(params);
        PageResult<ShopVo> pageResult = new PageResult<ShopVo>(list, startPage.getTotal(), pageable);
        return CommResult.success(pageResult);
    }


    @ApiOperation("查询名厨信息")
    @GetMapping("/find")
    @ApiImplicitParams({@ApiImplicitParam(name = "chefId", value = "名厨ID", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型{0:商品,1:名店,2:酒店,3:名厨,4.餐车}", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "typeId", value = "类型id", dataType = "String", paramType = "query")
    })
    public CommResult<BillChefAffiliated> find(Long chefId,Integer type,Long typeId,Pageable pageable) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (chefId!=null){
            params.put("chefId", chefId);
        }
        if (chefId!=null){
            params.put("type", type);
        }
        if (typeId!=null){
            params.put("typeId", typeId);
        }
        Page<Object> startPage = PageHelper.startPage(pageable.getPageNum(), pageable.getPageSize());
        List<BillChefAffiliated> list = billChefAffiliatedService.selectFindList(params);
        PageResult<BillChefAffiliated> pageResult = new PageResult<BillChefAffiliated>(list, startPage.getTotal(), pageable);
        return CommResult.success(pageResult);
    }

}
